package com.mrx;

import io.github.classgraph.ClassGraph;
import io.github.classgraph.ClassInfo;
import io.github.classgraph.ScanResult;

import java.io.BufferedReader;
import java.nio.file.Paths;
import java.util.List;

/**
 * @author Mr.X
 * @since 2024-11-04 11:34
 **/
public class ExampleMain {

    public static void main(String[] args) throws Exception {
        String java = Paths.get(System.getProperty("java.home"), "bin", "java").toAbsolutePath().toString();
        Process process = new ProcessBuilder(List.of(java, "--version")).start();
        System.out.println("*".repeat(100));
        try (BufferedReader reader = process.inputReader()) {
            char[] chars = new char[1024];
            int cnt;
            while ((cnt = reader.read(chars)) != -1) {
                System.out.println(new String(chars, 0, cnt));
            }
        }
        new ExampleMain().test();
    }

    private static void scanPackages() {
        try (ScanResult scanResult = new ClassGraph().enableAllInfo().scan()) {
            List<String> classNames = scanResult.getAllClasses()
                    .filter(it -> it.getPackageName().startsWith("com.sun.jna"))
                    .stream().map(ClassInfo::getName)
                    .toList();
            System.out.println(String.join("\n", classNames));
        }
    }

    public void test() {
        System.out.println("*".repeat(100));
    }

}